<?php


namespace app\index\controller;


use app\common\controller\BaseController;
use app\common\helper\util\Crypt;

class User extends BaseController
{

    /**
     * 注册
     *
     */
    function register(){
        $param = input();
        $data = \app\common\model\User::registerSuccess($param);
        if($data!=false){
            $this->result_success($data);
        }else{
            $this->result_error([],-2,"注册失败");
        }
    }
    function we_login(){

    }
    function sms_login(){

    }

    /**
     * 自动登录
     */
    function auto_login(){
        $data = \app\common\model\User::loginSuccess(\app\common\model\User::getById(1));
        $this->result_success($data);
    }

    /**
     * 登录
     */
    function login(){
        $param = input();
        if( !isset( $param["user_name"]) || !isset( $param["password"]) ){
            $this->result_error([],-1,"参数错误");
        }
        $param["password"] =  Crypt::pwd( $param["password"]);
        /** @var \app\common\model\User $user */
        $user = \app\common\model\User::simpleOne([
            "user_name"=>$param["user_name"],
            "password"=>$param["password"],
        ]);
        if($user){
            $data = \app\common\model\User::loginSuccess($user);
            $this->result_success($data);
        }else{
            $this->result_error([],-1,"密码错误");
        }
    }

    /**
     * 忘记密码
     */
    function forget_pwd(){
        $this->result_error([],-1,"请联系管理员");
    }
    /**
     * 忘记密码
     */
    function logout(){
        $data = \app\common\model\User::logoutSuccess();
        $this->result_success($data);
    }

}